<template>
  <div v-loading="loading" style="min-height: 60vh">
    <join1-form
      :title="title"
      :cat-id="catId"
      :join-type="joinType"
      :time-type="timeType"
      :data="data"
      @back="handleBack"
    />
  </div>
</template>

<script>
import Join1Form from '@/views/admin/tmpl/components/Join1Form'
import { apiFindTmpl } from '@/api/tmpl/tmpl'

export default {
  components: {
    Join1Form
  },
  data() {
    return {
      loading: false,
      // 详情数据
      data: {},
      title: '',
      joinType: 0,
      catId: '',
      timeType: 0
    }
  },
  created() {
    this.title = this.$route.params.title
    this.catId = this.$route.params.catId
    const joinType = this.$route.params.joinType
    const timeType = this.$route.params.timeType
    this.joinType = parseInt(joinType)
    this.timeType = parseInt(timeType)

    // 查找详情
    const id = this.$route.params.id
    if (id !== undefined) {
      this.fetchData(id)
    }
  },
  methods: {

    // 获取详情
    fetchData(id) {
      this.loading = true
      apiFindTmpl(id).then(res => {
        this.data = res.data
        this.title = this.data.title
        this.catId = this.data.catId
        this.joinType = this.data.joinType
        this.timeType = this.data.timeType
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },

    handleBack() {
      this.$router.push({ name: 'ExamTmpl' })
    }

  }
}
</script>
